<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/02/27 22:02:05 $)
// $RCSfile: cli_rebuildindex.php,v $ : $Revision: 1.1 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./modules/tickets/functions_maintenance.php");
require_once ("./modules/tickets/functions_search.php");
require_once ("./modules/tickets/functions_ticketsui.php");
require_once ("./modules/tickets/functions_clirebuildindex.php");
require_once ("./includes/functions_html.php");
$template->loadLanguageSection("cli_rebuildindex");

global $cli, $argv;

$_SWIFT["rebuild"] = array();
$_SWIFT["rebuild"]["percent"] = $_SWIFT["rebuild"]["processcount"] = 0;

if (intval($argv[2]) != 0)
{
	$_postpass = intval($argv[2]);
} else {
	$_postpass = 200;
}

// Empty the current Index
$cli->message($_SWIFT["language"]["emptyingindex"], CLI_OK);
emptyEntireSearchIndex();

$_tcount = $dbCore->queryFetch("SELECT COUNT(*) AS totalposts, MIN(ticketpostid) AS minticketpostid, MAX(ticketpostid) AS maxticketpostid FROM `". TABLE_PREFIX ."ticketposts`;");
$_totalposts = intval($_tcount["totalposts"]);
$_startat = intval($_tcount["minticketpostid"]);
$_finishat = intval($_tcount["maxticketpostid"]);
$_starttime = DATENOW;
$_wordcount = 0;

// Spit out some Info
$cli->message(sprintf($_SWIFT["language"]["indexinfo"], $_totalposts, $_startat, $_finishat), CLI_INFO);

while ($_SWIFT["rebuild"]["percent"] < 100)
{
//	echo "Start At: $_startat, Post Pass: $_postpass\n";
	$_startat = processPass($_startat, $_postpass, $_totalposts)+1;
}
?>